package framework.states;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

import framework.BasicFighter;
import framework.Controls;
import framework.ia.ReactorBrain;

public class FighterSelectIa extends FighterSelect {
	
	@Override
	public void update(GameContainer gc, StateBasedGame g, int delta)
			throws SlickException {
		if (selected1 && selected2) {
			BasicFighter f1 = fighters1[(int) cursor1.getY()][(int) cursor1.getX()];
			BasicFighter f2 = fighters2[(int) cursor2.getY()][(int) cursor2.getX()];
			useIa2 = new ReactorBrain(f2, f1);
		}
		super.update(gc, g, delta);
	}

	@Override
	public int getID() {
		return 15;
	}
	

	@Override
	public void controllerLeftPressed(int controller) {
		Controls c = this.caller.getAction(controller, "left");
		performAction(c);
	}

	@Override
	public void controllerRightPressed(int controller) {
		Controls c = this.caller.getAction(controller, "right");
		performAction(c);
	}

	@Override
	public void controllerButtonPressed(int controller, int button) {
		Controls c = this.caller.getAction(controller, "" + button);
		System.out.println(c);
		performAction(c);
	}

	public void performAction(Controls c) {
		if (c == null) {
			return;
		}
		switch(c) {
		case RIGHT_P1 :
			if (!selected2 && !selected1) {
				moveRight(cursor1);
			} else {
				moveRight(cursor2);
			}
		break;
		case LEFT_P1 :
			if (!selected2 && !selected1) {
				moveLeft(cursor1);
			} else {
				moveLeft(cursor2);
			}
		break;
		case START_P1 : case A_P1 : 
			selected2 = selected1;
			selected1 = true;
		break;
		case B_P1 :
			selected2 = false || transitioning;
			selected1 = selected2;
		break;
		default :
			break;
		}
	}

	@Override
	public void keyPressed(int key, char c) {
		super.keyPressed(key, c);
	}
}
